package com.ruoyi.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.user.domain.CustomerConfig;
import com.ruoyi.user.service.ICustomerConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客服设置Controller
 * 
 * @author DEREK
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/user/customer")
public class CustomerConfigController extends BaseController
{
    @Autowired
    private ICustomerConfigService customerConfigService;

    /**
     * 查询客服设置列表
     */
    @PreAuthorize("@ss.hasPermi('user:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerConfig customerConfig)
    {
        startPage();
        List<CustomerConfig> list = customerConfigService.selectCustomerConfigList(customerConfig);
        return getDataTable(list);
    }

    /**
     * 导出客服设置列表
     */
    @PreAuthorize("@ss.hasPermi('user:customer:export')")
    @Log(title = "客服设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerConfig customerConfig)
    {
        List<CustomerConfig> list = customerConfigService.selectCustomerConfigList(customerConfig);
        ExcelUtil<CustomerConfig> util = new ExcelUtil<CustomerConfig>(CustomerConfig.class);
        util.exportExcel(response, list, "客服设置数据");
    }

    /**
     * 获取客服设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customerConfigService.selectCustomerConfigById(id));
    }

    /**
     * 新增客服设置
     */
    @PreAuthorize("@ss.hasPermi('user:customer:add')")
    @Log(title = "客服设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerConfig customerConfig)
    {
        return toAjax(customerConfigService.insertCustomerConfig(customerConfig));
    }

    /**
     * 修改客服设置
     */
    @PreAuthorize("@ss.hasPermi('user:customer:edit')")
    @Log(title = "客服设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerConfig customerConfig)
    {
    	customerConfig.setBegTime(customerConfig.getBegTime().trim());
    	customerConfig.setEndTime(customerConfig.getEndTime().trim());
    	customerConfig.setWeek(customerConfig.getWeek().trim());
        return toAjax(customerConfigService.updateCustomerConfig(customerConfig));
    }

    /**
     * 删除客服设置
     */
    @PreAuthorize("@ss.hasPermi('user:customer:remove')")
    @Log(title = "客服设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerConfigService.deleteCustomerConfigByIds(ids));
    }
}
